<template>
	<view>
		<view class="page-foot"><view class="btn" @tap="sure">确定</view></view>
		<view class="container pt15 plr30">
			<view class="ques mb20 p30">
				<view class="flex flex-align-start mb20">
					<view class="label">问</view>
					<view class="fs32 col10">{{question.info.question}}</view>
				</view>
				<view class="fs22 col89">{{question.info.createtime_text}}</view>
			</view>
			<view class="box1 p30"><textarea class="textarea" value="" @input="inputanswer" placeholder="请输入"></textarea></view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	
	const functions = require('../../../utils/functions.js');
export default {
	data() {
		return {
			question_id:0,
			question:'',
			answer:''
		};
	},
	methods:{
		initData(){
			this.detail()
		},
		detail(){
			var that=this
			var question_id=that.question_id
			var json={
				id:question_id
			}
			functions.getAjaxList(that, '/api/xiluhouse/Question/question_detail', json, function (res) {
					
			
					
				that.question=res.data
			});
		},
		inputanswer(e){
			this.answer=e.detail.value
		},
		sure(){
			var that=this
			var answer=that.answer
			if(!answer){
				functions.toast('请输入回答内容');
				return false
			}
			var id=that.question_id
			var json={
				id:id,
				answer:answer
			}
			let pages = getCurrentPages(); // 页面栈数组，第一个元素为首页，最后一个元素为当前页面。
			let prevPage = pages[pages.length - 2]; // 上一页
			console.log(prevPage.$vm.questionList)
			var list=prevPage.$vm.questionList
			
			list.data.forEach(e=>{
				if(e.id==json.id){
					e.state=2
					  
				}
			})
			
			
			functions.getAjaxList(that, '/api/xiluhouse/Question/publish_answer', json, function (res) {
				functions.toast(res.msg);
				//更改上一页数据
				prevPage.$vm.questionList=list
				uni.navigateBack();
				 
				
			});
		}
		
	},
	onLoad(options){
		this.question_id=options.question_id
		this.initData()
	}
	
};
</script>

<style lang="scss" scoped>
.ques {
	background: #ffffff;
	box-shadow: 0 4rpx 30rpx 0 rgba(184, 189, 202, 0.3);
	border-radius: 10rpx;
}
.ques .label {
	margin-top: 5rpx;
	margin-right: 10rpx;
	width: 40rpx;
	height: 40rpx;
	background: linear-gradient(180deg, #00c4ff 0%, #0091ff 100%);
	border-radius: 10rpx;
	font-size: 24rpx;
	color: #ffffff;
	line-height: 40rpx;
	text-align: center;
}
.ques .btn1 {
	font-size: 22rpx;
	color: #ff723b;
	line-height: 30rpx;
}
.ques .btn2 {
	width: 100rpx;
	height: 50rpx;
	background: #0091ff;
	box-shadow: 0 4rpx 40rpx 0 rgba(3, 103, 179, 0.3);
	border-radius: 5rpx;
	font-size: 22rpx;
	color: #ffffff;
	line-height: 50rpx;
	text-align: center;
}
.box1 {
	width: 690rpx;
	height: 500rpx;
	background: #f6f7fa;
	border-radius: 10rpx;
}
.box1 .textarea {
	display: block;
	width: 100%;
	height: 100%;
	font-size: 28rpx;
	color: #333333;
	line-height: 40rpx;
}
.page-foot {
	padding: 0 40rpx 40rpx;
}
.page-foot .btn {
	width: 670rpx;
	height: 90rpx;
	border-radius: 10rpx;
	background: var(--blue);
	box-shadow: 0rpx 4rpx 40rpx rgba(3, 103, 179, 0.3);
	padding: 0;
	line-height: 90rpx;
	font-weight: normal;
	color: #fff;
	font-size: 30rpx;
	text-align: center;
}
</style>
